package com.sm.li.components;

import com.sm.li.entity.Admin;
import com.sm.li.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;


@Component
public class DemoScheduling {

//    @Autowired
    private AdminMapper adminMapper;

//    @Autowired
    private JavaMailSender javaMailSender;

//    @Autowired
    private EmailService emailService;


    //cron="秒 分 时 日 月 周 "
//    @Scheduled(cron = "0 15 16 4 * *")
    public void doSomeThing() throws Exception {
        //给这里面的员工发邮件
        List<Admin> admins = adminMapper.selectList(null);

        admins.forEach(admin -> {
            //使用异步线程池
            emailService.sendMail(admin);
        });
    }


}

